<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>结算台</title>
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  <script src="https://ad.aicebar.com/public/lib/js/vue.min.js"></script>
  <link href="https://ad.aicebar.com/public/lib/css/vant.min.css" rel="stylesheet">
  <script src="https://ad.aicebar.com/public/lib/js/vant.min.js"></script>
</head>

<body>
  <div id="app" v-cloak>

  </div>


  <!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js"></script> -->
  <script src="https://ad.aicebar.com/public/lib/js/axios.js"></script>
  <script src="../js/utils.js"></script>
  <script>
    var api = domain()
    var json = getQueryString()

    // var vConsole = new window.VConsole();
    // vConsole.destroy();


    new Vue({
      el: '#app',
      data() {
        return {
          type: '2',
          product: json.product_id,
          question: json.question_id || 0
        }
      },
      created() {
        this.handelSub()
      },

      methods: {
        handelSub() {
          var data = new FormData();
          data.append('product_id', this.product);
          // data.append('nums', 1);
          data.append('pay_type', 2);
          data.append('price', json.price)
          data.append('question_id', this.question);
          const headers = {
            'authorization': json.apiToken
          }
          axios.post(api + '/v1/subject/pay', data, {
            headers
          })
            .then((res) => {
              if (res.data.code === 2000) {
                var data = res.data.data
                this.handlePay(data)
              } else {
                this.$toast({
                  message: res.data.msg,
                  position: 'middle',
                  duration: 1000
                });
              }

            })
        },
        handlePay(data) {
          this.$toast.loading({
            mask: true,
            message: '加载中...'
          });
          this.wxExtPay(data)
        },

        wxExtPay(data) {
          // console.log(data)
          let str = data.h5_url + '&redirect_url=' + encodeURIComponent('https://shop.aicebar.com/report_h5/html/payConfirm.html?order=' + data.order_no)
          window.location.replace(str)
        },

      },
    });


  </script>
</body>

</html>